package com.xiaoy.core.side4.service;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springside.modules.persistence.DynamicSpecifications;
import org.springside.modules.persistence.SearchFilter;

import com.xiaoy.core.side4.dao.StudentDao;
import com.xiaoy.core.side4.entity.Student;

@Component
@Transactional
public class StudentService {

	private StudentDao dao;
	
	public Page<Student> filter (Map<String, Object> searchParams) {
		
		Map<String, SearchFilter> filters = SearchFilter.parse(searchParams);
		Specification<Student> spec = DynamicSpecifications.bySearchFilter(filters.values(), Student.class);
		
		System.out.println("dao-->"+dao);
		return dao.filterPage(spec, new PageRequest(1,2));
		
	}
	
	public StudentDao getDao() {
		return dao;
	}
	@Autowired(required=false)
	public void setDao(StudentDao dao) {
		this.dao = dao;
	}
	
	
}
